<template>
	<view class="page">
		<!--  v-model="dataList" @query="queryList" -->
		<pageTxt>
			<z-paging ref="paging" :paging-style="{ 'background-color': '#f7f7f7', height: '100%', width: '100%' }">
				<!-- 头部 -->
				<template slot="top">
					<view class="navbar-box" v-if="dataObj">
						<u-navbar :title="`“${dataObj.node_name}”复审`" :autoBack="true" :fixed="false"></u-navbar>
					</view>
				</template>
				<view class="add-content ios" v-if="dataObj">
					<u--form labelPosition="top" :model="jdysRuleForm" ref="uForm" labelWidth="auto">
						<template v-for="(item, index) in dataObj.criteria_list">
							<view class="form-box">
								<u-form-item labelPosition="top" labelWidth="100%" :key="index" v-if="item.content_type == 1" :required="item.is_required == 1" :label="`${index + 1}.${item.node_name}`">
									<text style="margin-bottom: 20rpx">{{ item.content || '未提交任何信息' }}</text>
									<view style="margin-bottom: 20rpx">
										<u-radio-group v-model="item.audit_state" placement="row" size="16px">
											<u-radio label="通过" :name="2"></u-radio>
											<u-radio label="拒绝" :name="3"></u-radio>
										</u-radio-group>
									</view>
									<u--textarea
										disableDefaultPadding
										v-model="item.reason_rejection"
										placeholder="审批意见"
										:placeholderStyle="{ fontSize: '13.5px', color: '#BFC4CC' }"
									></u--textarea>
								</u-form-item>
								<u-form-item labelPosition="top" labelWidth="100%" :key="index" v-else :required="item.is_required == 1" :label="`${index + 1}.${item.node_name}`">
									<view v-if="!item.node_files.length">未提交任何信息</view>
									<file-upload disabled :filesList="item.node_files" :type="3"></file-upload>
									<view style="margin: 20rpx 0">
										<u-radio-group v-model="item.audit_state" placement="row" size="16px">
											<u-radio label="通过" :name="2"></u-radio>
											<u-radio label="拒绝" :name="3"></u-radio>
										</u-radio-group>
									</view>
									<u--textarea
										disableDefaultPadding
										v-model="item.reason_rejection"
										placeholder="审批意见"
										:placeholderStyle="{ fontSize: '13.5px', color: '#BFC4CC' }"
									></u--textarea>
								</u-form-item>
							</view>
						</template>
					</u--form>
				</view>
				<view class="footer ios">
					<u-button
						text="提交"
						@click="submit"
						customStyle="width: 702rpx;height: 88rpx;background: #3B75FF;border-radius: 16rpx;font-weight: 500;font-size: 28rpx;color: #FFFFFF;margin:20rpx 24rpx;"
					></u-button>
				</view>
			</z-paging>
		</pageTxt>
	</view>
</template>

<script>
export default {
	data() {
		return {
			loading: false,
			dataObj: ''
		};
	},
	onLoad(option) {
		this.getProjectNodeDetails(option.id);
	},
	methods: {
		// 详情
		getProjectNodeDetails(node_id) {
			return new Promise((resolve, reject) => {
				this.$Apipc
					.getProjectNodeDetails({
						node_id
					})
					.then((res) => {
						console.log(res, '节点详情');
						if (res.code == 200) {
							res.data.criteria_list.forEach((item) => {
								item.audit_state = 2;
								item.reason_rejection = '';
							});
							this.dataObj = res.data;
						}
					});
			});
		},
		submit() {
			let dataObj = this.dataObj;
			for (let i = 0; i < dataObj.criteria_list.length; i++) {
				if (dataObj.criteria_list[i].audit_state == 3 && !dataObj.criteria_list[i].reason_rejection) {
					uni.showToast({
						title: '请输入拒绝理由',
						icon: 'error'
					});
					return;
				}
			}
			let data_arr = [];
			dataObj.criteria_list.forEach((item) => {
				data_arr.push({
					id: item.id,
					audit_state: item.audit_state,
					reason_rejection: item.reason_rejection || '' //item.audit_state == 3 ? item.reason_rejection : ''
				});
			});
			this.qualityAcceptanceRetrial({
				data_arr,
				project_id: dataObj.project_id,
				node_id: dataObj.id,
				node_data: dataObj
			});
		},
		// 初审
		qualityAcceptanceRetrial(data) {
			uni.showLoading({
				mask: true
			});
			this.$Apipc.qualityAcceptanceRetrial(data).then((res) => {
				console.log(res, '节点验收复审');
				uni.hideLoading();
				if (res.code == 200) {
					setTimeout(() => {
						var currentPages = getCurrentPages()[getCurrentPages().length - 2]
						if (currentPages) {
							uni.navigateBack({
								delta: 1
							});
						} else {
							uni.reLaunch({
								url: '/pages/index/index'
							});
						}
					}, 500);
				}
				uni.showToast({
					title: res.message,
					icon: res.code == 200 ? 'success' : 'error'
				});
			});
		}
	}
};
</script>

<style lang="scss" scoped>
::v-deep .u-textarea {
	padding: 20rpx !important;
}
::v-deep .u-form-item__body__left__content__label {
	margin-bottom: 14rpx !important;
}
</style>
